package com.easyattendance.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Type;


@Entity
@Table(name="TBL_ATTENDANCE")
@IdClass(StudentAttendancePK.class)
public class StudentAttendance
{
	@Id
	@Column(name="stud_roll_no",length=3,nullable=false)
	private int stud_roll_no;
	
	@Id
	@Column(name="class_id",length=15,nullable=false)
	private String class_id;
		
	@Id
	@Column(name="attendance_date",nullable=false)
	private Date attendance_date;
		
	@Column(name="attendance_status",nullable=false,length=1)
	private String attendance_status;
	
	@ManyToOne
	@JoinColumns({
	@JoinColumn(name="stud_roll_no",referencedColumnName="stud_roll_no",insertable=false,updatable=false),
	@JoinColumn(name="class_id",referencedColumnName="class_id",insertable=false,updatable=false)
	})
	private Student student;
	
	/*@ManyToOne
	@JoinColumn(name="class_id",referencedColumnName="class_id")
    private Class classObj; */

	/*@ManyToOne
	@JoinColumn(name="stud_roll_no", insertable=false,updatable=false,referencedColumnName="stud_roll_no")
    private Student stud; */
	
	public StudentAttendance() {
		super();
	}

    

	public int getStud_roll_no() {
		return stud_roll_no;
	}



	public void setStud_roll_no(int stud_roll_no) {
		this.stud_roll_no = stud_roll_no;
	}



	public String getClass_id() {
		return class_id;
	}



	public void setClass_id(String class_id) {
		this.class_id = class_id;
	}



	public Date getAttendance_date() {
		return attendance_date;
	}

	public void setAttendance_date(Date attendance_date) {
		this.attendance_date = attendance_date;
	}

	public String getAttendance_status() {
		return attendance_status;
	}

	public void setAttendance_status(String attendance_status) {
		this.attendance_status = attendance_status;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}



	public StudentAttendance(int stud_roll_no, String class_id,
			Date attendance_date, String attendance_status) {
		super();
		this.stud_roll_no = stud_roll_no;
		this.class_id = class_id;
		this.attendance_date = attendance_date;
		this.attendance_status = attendance_status;
	}



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((attendance_date == null) ? 0 : attendance_date.hashCode());
		result = prime * result
				+ ((class_id == null) ? 0 : class_id.hashCode());
		result = prime * result + stud_roll_no;
		result = prime * result + ((student == null) ? 0 : student.hashCode());
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		StudentAttendance other = (StudentAttendance) obj;
		if (attendance_date.equals(other.attendance_date) && class_id.equals(other.class_id) && stud_roll_no != other.stud_roll_no )
			return true;
		
		return true;
	}
	
	
	
}

